package com.share.trigger.job;

import com.share.domain.strategy.model.vo.StrategyAwardStockKeyVo;
import com.share.domain.strategy.service.IRaffleStock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务-异步更新数据库
 */
@Component
@Slf4j
public class updateAwardStockJob {
    @Resource
    private IRaffleStock raffleStock;

    @Scheduled(cron = "0/10 * * * * ?")
    public void exec(){
        try {
            StrategyAwardStockKeyVo strategyAwardStockKeyVo = raffleStock.takeQueueValue();
            if(strategyAwardStockKeyVo==null)return;
            log.info("定时任务，更新奖品消耗库存 strategyId:{},awardId:{}",strategyAwardStockKeyVo.getStrategyId(),strategyAwardStockKeyVo.getAwardId());
            raffleStock.updateStrategyAwardStock(strategyAwardStockKeyVo.getStrategyId(), strategyAwardStockKeyVo.getAwardId());
        } catch (InterruptedException e) {
            log.info("定时任务，更新奖品消耗库存失败",e);
        }
    }
}
